/*
 * @Description: 根据模块化封装
 * @Author:  zhangweigang
 * @Date: 2021-03-09 21:59:41
 * @LastEditTime: 2021-04-11 12:13:47
 * @LastEditors: zhangweigang
 */
import { request } from './reuqest.js';
import qs from 'qs';

// 代理跟路径
const api = '/api';

// 获取用户所有信息
export function getUserAllInfo() {
  return request({
    url: api + '/users',
    method: 'GET'
  });
}

// 用户注册
export function userRegisterInfo(params) {
  return request({
    url: api + '/users',
    method: 'POST',
    data: params
  });
}

// 用户登录
export function userLoginStart(params) {
  console.log(params, '登录参数');
  return request({
    url: api + '/sys/login',
    method: 'POST',
    data: qs.stringify(params)
  });
}

// 修改用户信息
export function updateUserInfo(params) {
  console.log(params, '用户信息修改');
  return request({
    url: api + '/users',
    method: 'PUT',
    data: params
  });
}

// 修改密码
export function modifyPassWorldInfo(params) {
  console.log(params, '密码参数！');
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    },
    url: api + '/users/repassword',
    method: 'PATCH',
    data: qs.stringify(params)
  });
}

// 书籍上传
export function uploadBookInfo(params) {
  return request({
    headers: {
      'Content-Type': 'form-data'
    },
    url: api + '/bsBook/upload',
    method: 'POST',
    data: params
  });
}

// 书籍上传 基本信息2
export function uploadBookBaseInfo(params) {
  return request({
    headers: {
      'Content-Type': 'form-data'
    },
    url: api + '/bsBook/upload1',
    method: 'POST',
    data: params
  });
}

// 获取书籍列表  2021-04-04 暂时不用
// export function getBookListInfo() {
//   return request({
//     url: api + '/bsBook/selectPageByParam',
//     method: 'POST',
//     data: {}
//   });
// }

// 书籍分页数据
export function getBookPagination(pageNum, pageSize, isShare) {
  return request({
    url: api + '/bsBook/selectPageByParam?pageNum=' + pageNum + '&' + 'pageSize=' + pageSize,
    method: 'POST',
    data: { isShare }
  });
}

// 我的上传书籍分页列表
export function getMyBookPagination(pageNum, pageSize) {
  return request({
    url: api + '/bsBook/mineShare?pageNum=' + pageNum + '&' + 'pageSize=' + pageSize,
    method: 'POST',
    data: {}
  });
}

// 修改共享状态
export function modifyShareStatus(params) {
  return request({
    url: api + '/bsBook',
    method: 'PUT',
    data: params
  });
}

// 根据书籍名称查询书籍信息
export function getBookByName(name) {
  return request({
    url: api + '/bsBook/selectPageByParam',
    method: 'POST',
    data: name
  });
}

// 留言提交
export function submitLeaveMessage(params) {
  return request({
    url: api + '/bsComment',
    method: 'POST',
    data: params
  });
}

// 我的留言列表数据
export function getLeaveInfoData() {
  return request({
    url: api + '/bsComment/selectPageByParam',
    method: 'POST',
    data: {}
  });
}

// 获取通知公告的所有数据
export function getAnnounceAllData() {
  return request({
    url: api + '/bsNotice/selectPageByParam',
    method: 'POST',
    data: {}
  });
}

// 当前用户的历史留言分页查询 -- 后台根据 userId 查询当前用户的留言
export function getLeavePagination(pageNum, pageSize) {
  console.log(pageNum, pageSize, '获取分页参数！');
  return request({
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    url: api + '/bsComment/selectMineByParam?pageNum=' + pageNum + '&' + 'pageSize=' + pageSize,
    method: 'POST',
    data: {}
  });
}

// 通知公告分页查询
export function getAnnouncePagination(pageNum, pageSize) {
  console.log(pageNum, pageSize, '获取分页参数！');
  return request({
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    url: api + '/bsNotice/selectPageByParam?pageNum=' + pageNum + '&' + 'pageSize=' + pageSize,
    method: 'POST',
    data: {}
  });
}

// 查询通知公告内容详情
export function getAnnounceByIdDetail(id) {
  return request({
    url: api + '/bsNotice/selectOne',
    method: 'GET',
    params: {
      id
    }
  });
}

// 获取所有分类
export function getCateInfo() {
  return request({
    url: api + '/bsBookCategory/selectAll',
    method: 'GET'
  });
}

// 评论回复
export function replyLeaveInfo(params) {
  return request({
    url: api + '/bsReply',
    method: 'POST',
    data: params
  });
}

// 单个帖子回复查询
export function getSoleReplayInfo(id) {
  return request({
    url: api + '/bsReply/selectTreeData',
    method: 'GET',
    params: { commentId: id }
  });
}
